// pages/malltaskPackage/pages/mall/mall.js
const app = getApp();
const quote = app.globalData.quote;
const path = quote.paths;
const util = require('../../../../utils/util.js');
const tools = require('../../../../utils/tools.js');
const api = require('../../../../utils/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dsds:11122222, 
    isIpx: app.globalData.isIpx,
    dialogueID: 0, //全部商品分类id
    storyID: 3, //vip专场分类id
    cateID: 0, //当前分类id
    page: 0, //页码
    pageSize: 5, //页大小
    CommodityList: [], //商品列表数据
    noMoreData: false, //false表示还有数据,true表示没有更多数据
    Gold:null,
    IsVip:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    that.getVideoList();
    that.getuser()

  },
  //跳转vip注册页面
  goVip: function() {
    wx.navigateTo({
      // url: '../../malltaskPackage/pages/task/task',
    })
  },
  //跳转任务界面
  obtain: function() {
    wx.navigateTo({
      url: '../../../malltaskPackage/pages/task/task',
    })
  },
  //跳转订单界面
  goOrder: function() {
    wx.navigateTo({
      url: '../../../malltaskPackage/pages/order/order',
    })
  },
  // 更改当前分类id
  changeCateID(e) {
    console.log(e)
    this.setData({
      cateID: e.currentTarget.dataset.id,
      page: 0,
      CommodityList: [],
      isData: false,
    })
    this.getVideoList();

  },
  //获取用户金币等级
  getuser: function () {
    var that = this
    let dataDic = {
      UCUID: app.globalData.UCUID
    };
    api.methodEnglishCorner_MyPersonalInformation({
      dataDic,
      success: function (res) {
        var bar = (res.data.data.Experience / res.data.data.UpgradeExperience) * 100
        console.log(bar)
        console.log(res.data, '91用户资料')
        that.setData({
        //  bar: bar,
          IsVip: res.data.data.IsVip,
          Gold: res.data.data.Gold,
        //  Rank: res.data.data.Rank,
        //  UpgradeExperience: res.data.data.UpgradeExperience
        })
      }
    })
  },
  // 获取商品列表

  getVideoList: function() {
    let that = this;
    if (this.data.isData) {
      return
    }
    wx.showLoading({
      title: '加载中',
    })

    let dataDic = {

      CommodityType: that.data.cateID,
      pageIndex: that.data.page,
      pageSize: that.data.pageSize
    };
    api.methodEnglishCorner_CommodityList({
      dataDic,
      success: (res) => {
        console.log(res.data.data.CommodityList, '商品列表115')
        wx.hideLoading();
        let length = res.data.data.CommodityList.length;
        if (length == 0) {
          this.setData({
            isData: true
          })
        }
        for (let i = 0; i < length; i++) {
          res.data.data.CommodityList[i].CommodityImageUrl = app.globalData.imgUrl + res.data.data.CommodityList[i].CommodityImageUrl;

        }
        that.setData({
          page: that.data.page + 1,
          //CommodityList: res.data.data.CommodityList
          CommodityList: that.data.CommodityList.concat(res.data.data.CommodityList)
        })
      }
    })
  },
  //进入商品详情 url: '/pages/unit/unit?Data=' + data 
  mallDetails: function(e) {

    console.log('进入详情页')
    console.log(e.currentTarget.dataset.id)
    var CommodityId = e.currentTarget.dataset.id

    var dataDic = {

      CommodityId: CommodityId
    };
    api.methodEnglishCorner_CommodityInfo({
      dataDic,
      success: function(res) {
        console.log('114商品详情数据', res.data)
        let length = res.data.data.CommodityImageList.length;
        for (let i = 0; i < length; i++) {
          res.data.data.CommodityImageList[i].ImageUrl = app.globalData.imgUrl + res.data.data.CommodityImageList[i].ImageUrl;

        }
        var commodity = JSON.stringify(res.data)

        wx.navigateTo({
          url: '../../../malltaskPackage/pages/mallDetail/mallDetail?commodity=' + commodity
        })
      }

    })

  },
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    console.log('滚到底部了')
    this.getVideoList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})